package com.api.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${file.upload-dir:uploads/avatars}")
    private String uploadDir;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String absolutePath = new File("").getAbsolutePath();
        String path = "file:" + absolutePath + File.separator + uploadDir + File.separator;
        System.out.println("配置静态资源映射: /api/files/avatars/** -> " + path);
        
        registry.addResourceHandler("/api/files/avatars/**")
                .addResourceLocations(path);
    }
} 